package com.min.uitest.ui

import androidx.compose.foundation.background
import androidx.compose.foundation.layout.*
import androidx.compose.material.*
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.Menu

import androidx.compose.runtime.Composable
import androidx.compose.runtime.SideEffect
import androidx.compose.runtime.getValue
import androidx.compose.runtime.rememberCoroutineScope
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.res.stringResource

import androidx.compose.ui.unit.dp
import androidx.navigation.compose.currentBackStackEntryAsState
import androidx.navigation.compose.rememberNavController
import com.google.accompanist.insets.ProvideWindowInsets
import com.google.accompanist.systemuicontroller.rememberSystemUiController
import com.min.uitest.NavController
import com.min.uitest.NavControllerCompose
import com.min.uitest.R
import com.min.uitest.ui.customcp.InsetAwareTopAppBar
import com.min.uitest.ui.theme.UseUiTestTheme
import kotlinx.coroutines.launch


@Composable
fun FirstAppUi() {
    UseUiTestTheme {
        //加上这个是为了控制顶部区域
        ProvideWindowInsets {
            val systemUiController = rememberSystemUiController()
            SideEffect {
                systemUiController.setSystemBarsColor(color = Color.Transparent, darkIcons = false)
            }
            val coroutineScope = rememberCoroutineScope()
            val scaffoldState = rememberScaffoldState()
            val navController = rememberNavController()
            val navBackStackEntry by navController.currentBackStackEntryAsState()
            val currentRoute =
                navBackStackEntry?.destination?.route ?: NavControllerCompose.STATIC_UI_NORMAL

            Scaffold(
                scaffoldState = scaffoldState,
                drawerContent = {
                    AppDrawer(
                        currentRoute = currentRoute,
                        navigateToHome = { navController.navigate(NavControllerCompose.STATIC_UI_NORMAL) },
                        navigateToInterests = { navController.navigate(NavControllerCompose.DYNAMIC_UI_LIST) },
                        closeDrawer = { coroutineScope.launch { scaffoldState.drawerState.close() } }
                    )
                },

                //标题栏区域,这样写会有
               /* topBar = {

                    Column() {

                        TopAppBar(
                            title = { Text(text = "标题栏") },
                            navigationIcon = {
                                IconButton(
                                    onClick = {
                                        coroutineScope.launch { scaffoldState.drawerState.open() }

                                    }
                                ) {
                                    Icon(
                                        imageVector = Icons.Filled.Menu,
                                        contentDescription = null
                                    )
                                }
                            }
                        )
                    }
                },*/

                //悬浮按钮
                floatingActionButton = {
                    ExtendedFloatingActionButton(
                        text = { Text("悬浮按钮") },
                        onClick = { }
                    )
                },
                floatingActionButtonPosition = FabPosition.End
            ) {

                val coroutineScope = rememberCoroutineScope()

                // 此处加上这个是为了让
                Scaffold(
                    scaffoldState = scaffoldState,
                    topBar = {
                        val title = stringResource(id = R.string.app_name)
                        InsetAwareTopAppBar(
                            title = { Text(text = title) },
                            navigationIcon = {
                                IconButton(onClick = { coroutineScope.launch { scaffoldState.drawerState.open() } }) {
                                    Icon(
                                        painter = painterResource(R.drawable.ic_jetnews_logo),
                                        contentDescription = "Open navigation drawer"
                                    )
                                }
                            }
                        )
                        Column(modifier = Modifier.background(color = Color.Red)) {

                        }
                    }
                ) {
                    //NavController()
                    Column(modifier = Modifier.fillMaxSize().background(color = Color.LightGray)) {
                        
                    }
                }

            }
        }
    }


}